<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<table class="table table-bordered table-condensed table-hover tb">
	<tr>
		<td>部门</td>
		<td>姓名</td>
		
		<td>总经理</td>
		<td>部门负责人</td>
		<td>片区负责人</td>
		<td>服务部负责人</td>
		<td>组训</td>
		<td>综合内勤</td>
		<td>编辑</td>
		<!-- <td>编辑</td> -->
	</tr>
	 <c:forEach items="${txlList }" var="txl"> 
		<tr id=${txl.id1 }>
			<td>${txl.bumen }</td>
			<td>${txl.name }</td>

			<c:forEach items="${txl.zhiweiMap }" var="zhiweiMap">
				<td>
					<label class="checkbox inline"></label>
					<input type="checkbox" name="zhiwei"  value="${zhiweiMap.key}" <c:if test="${zhiweiMap.value}">checked="checked"</c:if> >
				</td>
			</c:forEach>
			<td>
				<input type = "button" value = "提交"  onclick="editzhiwei(this);" class="btn btn-primary" >
			</td>
		</tr>
	</c:forEach>
</table>
<script type="text/javascript">

	function editzhiwei(btn){
		var $row=$($(btn).parents("tr"));
		var id1=$row.attr("id");
		var zhiwei=getZhiwei($row);
		
		$.post("updateTxl",{
			id1:id1,
			zhiwei:zhiwei
		},function(data){
			alert(data);
		}); 
	}
	
	function getZhiwei(row){
		
		var zhiwei="";
		var $cks=row.find("input[type='checkbox'][name='zhiwei']:checked");
		var len = $cks.length;
		if(len==0){
			return null;
		}else{
			$cks.each(function(index){
	   			if(index==len-1){
	   				zhiwei+=$(this).val();
	   			}else{
	   				zhiwei+=$(this).val()+",";
	   			} 
			});
		}
		return zhiwei;
	}
	</script>
